package demo.java.java8.Lambdas.demo6;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collector;
import java.util.stream.Collectors;
import static java.util.stream.Collector.Characteristics.*;

public class ToListCollector<T> implements Collector<T, List<T>, List<T>>{

	@Override
	public BiConsumer<List<T>, T> accumulator() {
		return List::add;
	}

	@Override
	public Set<java.util.stream.Collector.Characteristics> characteristics() {
		return null;
	}

	@Override
	public BinaryOperator<List<T>> combiner() {
		return (list1,list2) ->  {
			list1.addAll(list2);
			return list1;
		};
	}

	@Override
	public Function<List<T>, List<T>> finisher() {
		return Function.identity();
	}

	@Override
	public Supplier<List<T>> supplier() {
		return ArrayList::new;
	}
	

}
